package com.leyou.search.controller;

import com.leyou.item.dto.SpuDTO;
import com.leyou.search.dto.SearchParamDTO;
import com.leyou.search.entity.Goods;
import com.leyou.search.service.SearchService;
import com.leyou.starter.elastic.entity.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Map;

/**
 * @author ：qcq
 * @date ：Created in 2020/12/13 9:27
 * @description：
 */
@RestController
@RequestMapping("/goods")
public class SearchController {

    @Autowired
    private SearchService searchService;

    /**
     * 搜索提示
     *
     * @param key
     * @return
     */
    @GetMapping("/suggestion")
    public Mono<List<String>> getSuggestion(@RequestParam("key") String key) {
        return searchService.getSuggestion(key);
    }

    @PostMapping("/list")
    public Mono<PageInfo<Goods>> searchGoods(@RequestBody SearchParamDTO searchParamDTO) {
        return searchService.searchGoods(searchParamDTO);
    }

    @PostMapping("/filter")
    public Mono<Map<String, List<?>>> listFilter(@RequestBody SearchParamDTO searchRequest) {
        return this.searchService.listFilter(searchRequest);
    }

}
